home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 24
/
Amiga Format AFCD24 (Feb 1998, Issue 108).iso
/
-seriously_amiga-
/
shareware
/
programming
/
other
/
apic
/
examples
/
helloworld.lst
< prev
next >
Wrap
File List
|
1998-01-05
|
10KB
|
253 lines
#PIC V1.0 (c)1997 J.Petroglou LIST FILE
#file: dh2:IDE/APICforAMINET/APIC/examples/HelloWorld.src
#date: Sun Dec 14 20:42:20 1997
#pic : PIC16C84
ADDR CODE SRCLINE SOURCECODE
0000 000001
0000 000002
0000 000003
0000 000004
0000 000005 ;this is a hello world program written in microchip assembler,
0000 000006 ;
0000 000007 ;the string is transmitted serial to an terminal. the baudrate is
0000 000008 ;determined by the value of "bitcntr", loaded with "delay"
0000 000009 ;19200 at 4 MHz clock speed needs at all 52 cycles pro bit
0000 000010 ;
0000 000011 ;after sending all characters pic runs an endless loop, a reset is necessary
0000 000012 ;to send string again. this reset is performed by a watchdog time out. the
0000 000013 ;watchdogtimer is set to 2.3 seconds (128 * 18 ms)
0000 000014 ;
0000 000015 ;string lenght is defined by a zero byte at end of string
0000 000016 ;
0000 000017 ;
0000 000018 ; http://linux.rz.fh-hannover.de/~duesterb/
0000 000019
0000 000020
0000 000021
0000 000022
0000 000023 list p=pic16c84, r=dec, s=off ;radix = decimal
0000 000024 ;case sensitivity=off
0000 000025
0000 000026 back
0000 000027
0000 000028
0000 000029 clockspeed = 4000000 ;clockspeed is 4 Mhz
0000 000030 baudrate = 19200 ;enter baudrate here
0000 000031
0000 000032 delay = (clockspeed/4/baudrate-12)/4 ;value for baudrate, 12 cycles fixed, 4 cycles delay
0000 000033
0000 000034 ram = 0ch ;beginning of RAM register
0000 000035
0000 000036 #define happy
0000 000037
0000 000038
0000 000039 CBLOCK ram
0000 000040
0000 000040
0000 000041 delaycntr ;bit dely counter
0000 000042 charcntr ;counter shows actual character of string
0000 000043 bitcntr ;counter shows actual bit of byte
0000 000044 xmitdata ;data to transmit
0000 000045
0000 000045
0000 000046 ENDC
0000 000047
0000 000048
0000 000049
0000 000050
0000 000051 PC = 02h ;programcounter
0000 000052 PortA = 05h ;register 05h is PortA
0000 000053
0000 000054
0000 000055
0000 000056 #define TXD PortA,0 ;TXD line is bit 0 from Port A
0000 000057 #define c 03h,0 ;carry bit is bit 0 from status register
0000 000058 #define z 03h,2 ;zero bit is bit 2 from status register
0000 000059
0000 000060
0000 000061
0000 000062
0000 000063 ; Remember to change device info if programming a different PIC. Do not use RC
0000 000064 ; devices. Their clock speed is not sufficiently accurate or stable for serial
0000 000065 ; communication.
0000 000066
0000 000067
0000 000068
0000 3000 000069 begin movlw 0 ;move 0 to tristate register, set port to output.
0001 0065 000070 tris PortA
0002 000071
0002 018D 000072 clrf charcntr ;we start at the first character
0003 000073
0003 000074
0003 3008 000075 send_byte movlw 8h ;Eight bits in a byte.
0004 008E 000076 movwf bitcntr
0005 000077
0005 2020 000078 call string ;Get character from string.
0006 008F 000079 movwf xmitdata ;Put character into the transmit byte.
0007 000080
0007 088F 000081 movf xmitdata,f ;test xmitdata on zero
0008 1903 000082 btfsc z
0009 2819 000083 goto endless ;do endless loop if xmitdata was zero
000A 000084
000A 000085
000A 1405 000086 bsf TXD ;set TXD line, dirct connection
000B 000087
000B 0A8D 000088 incf charcntr,f ;next position of string.
000C 000089
000C 201A 000090 call bitdelay ;Start bit. ((delay * 4) + 4) cycles
000D 000091
000D 000092
000D 000093
000D 0C8F 000094 xmit rrf xmitdata,f ;Rotate right moves data bits into
000E 000095 ;carry, starting with bit 0.
000E 000096
000E 1803 000097 btfsc c ;clear TXD if carry bit is set
000F 1005 000098 bcf TXD
0010 1C03 000099 btfss c ;set TXD if carry bit is clear
0011 1405 000100 bsf TXD
0012 000101
0012 000102
0012 000103
0012 201A 000104 call bitdelay ;Data bit.
0013 000105
0013 0B8E 000106 decfsz bitcntr,f ;Not eight bits yet? Send next data bit
0014 280D 000107 goto xmit
0015 000108
0015 1005 000109 bcf TXD ;clear TXD
0016 000110
0016 000111
0016 000112
0016 201A 000113 call bitdelay ;Stop bit. ((delay * 4) + 4) cycles
0017 201A 000114 call bitdelay ;Stop bit. ((delay * 4) + 4) cycles
0018 000115
0018 000116
0018 2803 000117 goto send_byte ;goto send_byte if line feed is not send
0019 000118
0019 000119
0019 000120
0019 000121
0019 2819 000122 endless goto endless ;Endless loop. Reset controller to run
001A 000123 ;program again.
001A 000124
001A 000125
001A 000126
001A 000127
001A 000128
001A 000129
001A 000130
001A 000131
001A 000132
001A 000133
001A 000134 ; To change the baud rate, substitute a new value for bitdelay at the beginning of
001A 000135 ; this program.
001A 000136
001A 000137
001A 000138
001A 300A 000139 bitdelay movlw delay ;this bitdelay delays ((delay * 4) + 4) cycles
001B 008C 000140 movwf delaycntr
001C 0000 000141 :loop nop
001D 0B8C 000142 decfsz delaycntr,f
001E 281C 000143 goto :loop ;this is an local loop
001F 3400 000144 retlw 0
0020 000145
0020 000146
0020 000147
0020 000148
0020 000149
0020 000150
0020 000151
0020 080D 000152 string movf charcntr,w
0021 0782 000153 addwf PC,f ;String consisting of "Hello world"
0022 000154 ;followed by a linefeed.
0022 000155
0022 000156
0022 000157
0022 000158
0022 000160
I`m happy
0022 000164
0022 3448 000165 retlw "Hello world",0ah,0ah ;string, two linefeeds
0023 3465 000165
0024 346C 000165
0025 346C 000165
0026 346F 000165
0027 3420 000165
0028 3477 000165
0029 346F 000165
002A 3472 000165
002B 346C 000165
002C 3464 000165
002D 340A 000165
002E 340A 000165
002F 000166
002F 000168
002F 000170
002F 000172
002F 000173
002F 340D 000174 retlw 0dh,0 ;one cr, Zerobyte => stop sending
0030 3400 000174
0031 000175
0031 000176
0031 000177
0031 000178
0031 000179 end
Used Symbols
-----------------------------------------
back 00000000
clockspeed 003D0900
baudrate 00004B00
delay 0000000A
ram 0000000C
delaycntr 0000000C
charcntr 0000000D
bitcntr 0000000E
xmitdata 0000000F
PC 00000002
PortA 00000005
begin 00000000
send_byte 00000003
xmit 0000000D
endless 00000019
bitdelay 0000001A
string 00000020
Used Defines
-----------------------------------------
happy
c 03h,0
z 03h,2
TXD PortA,0
PROGRAM MEMORY USAGE TABLE: '-' = not used 'X' = used
0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX X---------------
0040 : ---------------- ---------------- ---------------- ----------------
0080 : ---------------- ---------------- ---------------- ----------------
00C0 : ---------------- ---------------- ---------------- ----------------
0100 : ---------------- ---------------- ---------------- ----------------
0140 : ---------------- ---------------- ---------------- ----------------
0180 : ---------------- ---------------- ---------------- ----------------
01C0 : ---------------- ---------------- ---------------- ----------------
0200 : ---------------- ---------------- ---------------- ----------------
0240 : ---------------- ---------------- ---------------- ----------------
0280 : ---------------- ---------------- ---------------- ----------------
02C0 : ---------------- ---------------- ---------------- ----------------
0300 : ---------------- ---------------- ---------------- ----------------
0340 : ---------------- ---------------- ---------------- ----------------
0380 : ---------------- ---------------- ---------------- ----------------
03C0 : ---------------- ---------------- ---------------- ----------------
Program Memory Words Used: 0049
Program Memory Words Free: 0975
Errors: 0